import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaDialog, WeaRightMenu, WeaNewScroll, WeaFormItem, WeaSearchGroup, WeaSelect, WeaBrowser, WeaScope, WeaSelectGroup, WeaAuth } from 'ecCom';
import { Button, Row, Col } from 'antd';
import { WeaTableNew, WeaSwitch } from 'comsMobx';

const WeaTable = WeaTableNew.WeaTable;
import { toJS } from 'mobx';
import equal from 'deep-equal';
import _ from 'lodash';
import CrmShowGroup from '../comp/crm-show-group';
import WeaCustomerShareTableEdit from '../comp/WeaCrmTableEdit/customerShare.js';
import { WeaLocaleProvider } from 'ecCom';

const getLabel = WeaLocaleProvider.getLabel;

@observer
class ContractShare extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      datas: props.data || [],
    };
  }
  componentWillReceiveProps(nextProps) {
    this.setState({ datas: nextProps.data });
  }
  shouldComponentUpdate() {
    return true;
  }
  render() {
    const { condition, onCancel } = this.props;
    const { datas } = this.state;
    const columns = [
      {
        title: getLabel(21956, '对象类型'),
        com: [{ label: '', type: 'INPUT', viewAttr: 1, key: 'sharetypespan', disabled: false }],
        width: '20%',
        dataIndex: 'sharetypespan',
        key: 'sharetypespan',
      },
      {
        title: getLabel(106, '对象'),
        com: [{ label: '', type: 'INPUT', viewAttr: 1, key: 'shareidspan', disabled: false }],
        width: '30%',
        dataIndex: 'shareidspan',
        key: 'shareidspan',
      },
      {
        title: getLabel(683, '安全级别'),
        com: [{ label: '', type: 'INPUT', viewAttr: 1, key: 'seclevelspan', disabled: false }],
        width: '30%',
        dataIndex: 'seclevelspan',
        key: 'seclevelspan',
      },
      {
        title: getLabel(3005, '共享级别'),
        com: [{ label: '', type: 'INPUT', viewAttr: 1, key: 'sharelevelspan', disabled: false }],
        width: '20%',
        dataIndex: 'sharelevelspan',
        key: 'sharelevelspan',
      },
    ];
    const that = this;
    return (
      <div >
        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@kzvjap`} height={'100%'}>
          <div >
            <CrmShowGroup ecId={`${this && this.props && this.props.ecId || ''}_CrmShowGroup@3ob2kl`} needTigger leftComponent={getLabel(1361, '基本信息')} showGroup >
              <WeaAuth
                ecId={`${this && this.props && this.props.ecId || ''}_WeaAuth@97sxyg`}
                visible
                ref="customerShare"
                type="form"
                className="crm-auth-customersize"
                icon={'icon-coms-fa'}
                iconBgcolor="#f14a2d"
                conditions={condition}
                title={getLabel(2112, '共享设置')}
                onOk={(v) => {
                  if (typeof (v.seclevel) !== 'undefined') { v.seclevelspan = `${v.seclevel} - ${v.seclevelMax}`; }
                  // console.log(v);
                  v.shareid = v.relatedshareid;
                  v.shareidspan = v.relatedshareidspan;
                  datas.push(v);
                  that.setState({ datas });
                  { typeof this.props.saveCurrentDatas === 'function' && this.props.saveCurrentDatas(datas); }
                }}
                onCancel={() => {}}
              />
            </CrmShowGroup>
            <WeaCustomerShareTableEdit
              ecId={`${this && this.props && this.props.ecId || ''}_WeaCustomerShareTableEdit@cbxrs7`}
              title={getLabel(1279, '共享信息')}
              showGroup
              needAdd
              needCopy={false}
              columns={columns}
              datas={datas}
              canAdd
              addColumns={this.addColumns.bind(this)}
              onChange={this.editTableDatas.bind(this)}
            />
          </div>
        </WeaNewScroll>
      </div>
    );
  }
  // getBottomButtons(){
  //     const {onCancel,onSave} = this.props;
  //     const {datas} = this.state;
  //     let btnArr = [];
  //     btnArr.push(<Button  type="primary" onClick={()=>{typeof onSave === 'function' && onSave(datas);this.setState({datas:[]});}}>{getLabel(86,"保存")}</Button>)
  //     btnArr.push(<Button  type="primary" onClick={()=>{typeof onCancel === 'function' && onCancel();}}>{getLabel(309,"关闭")}</Button>)
  //     return btnArr;
  // }

  addColumns() {
    this.refs.customerShare.onOk();
  }
  editTableDatas(data) {
    this.setState({ datas: data });
    { typeof this.props.saveCurrentDatas === 'function' && this.props.saveCurrentDatas(data); }
  }
}

export default ContractShare;
